module.exports = function(req, res, next) {
    var domain = require('domain');
    var loggers = require('../lib/loggers');

    var outputLogger = loggers.output;
    var d = domain.create();

    d.on('error', function(err) {
        outputLogger.error(err);
        res.json({
            successful: false,
            error: {
                id: 1,
                message: 'Unknown exception'
            },
            data: {
                exception: err
            }
        });
    });

    d.run(function() {
        next();
    });
};
